package com.sxg.controller;

import com.sxg.query.SxgGoodsDetailQuery;
import com.sxg.utils.code.AjaxResult;
import com.sxg.vo.SxgGoodsDetailVO;
import lombok.AllArgsConstructor;
import com.sxg.page.PageResult;
import com.sxg.utils.code.Result;
import com.sxg.service.SxgGoodsDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 商品详情信息
 *
 * @author 浪漫写尽歌谱 3298751420@qq.com
 * @since 1.0.0 2024-03-07
 */
@RestController
@RequestMapping("sxg/sxg_goods_detail")
@AllArgsConstructor
public class SxgGoodsDetailController {
    private final SxgGoodsDetailService sxgGoodsDetailService;

    @GetMapping("page")
    @PreAuthorize("hasAuthority('sxg:sxg_goods_detail:page')")
    public Result<PageResult<SxgGoodsDetailVO>> page(@Valid SxgGoodsDetailQuery query) {
        PageResult<SxgGoodsDetailVO> page = sxgGoodsDetailService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    public AjaxResult get(@PathVariable("id") Long id) {
        return sxgGoodsDetailService.getDetailByGoodsId(id);
    }

    @PostMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_detail:save')")
    public Result<String> save(@RequestBody SxgGoodsDetailVO vo) {
        sxgGoodsDetailService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_detail:update')")
    public Result<String> update(@RequestBody @Valid SxgGoodsDetailVO vo) {
        sxgGoodsDetailService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @PreAuthorize("hasAuthority('sxg:sxg_goods_detail:delete')")
    public Result<String> delete(@RequestBody List<Long> idList) {
        sxgGoodsDetailService.delete(idList);

        return Result.ok();
    }
}